#include "qdouble.h"

static int dispatchOperation(
	const NumericValue* self, const NumericValue* n, 
	char op, NumericValue* result)
{
	return n->type->doubleOperation(n, op, self->doubleVal, result);
}

static int doubleOperation(
	const NumericValue* self, char op, gdouble n, NumericValue* result)
{
	switch (op)
	{
	case '=' : result->doubleVal = n; return 0;
	case '*' : *result = *self; result->doubleVal *= n; return 0;
	case '/' : *result = *self; result->doubleVal /= n; return 0;
	case '+' : *result = *self; result->doubleVal += n; return 0;
	case '-' : *result = *self; result->doubleVal -= n; return 0;
	case '%' : break;
	case '|' : break;
	case '&' : break;
	}
	return -1;
}

static int int32Operation(
	const NumericValue* self, char op, gint32 n, NumericValue* result)
{
	return doubleOperation(self, op, n, result);
}

const QDoubleType qdoubleType = {
	dispatchOperation, int32Operation, doubleOperation
};

static const QDouble prototype = { &qdoubleType.super, 0 };

extern QDouble* QDouble_init(QDouble* self)
{
	*self = prototype;
	return self;
}

extern QDouble* QDouble_init2(QDouble* self, gdouble value)
{
	*self = prototype;
	self->super.doubleVal = value;
	return self;
}